package com.ll.domain.classbase.convert;

import com.ll.app.api.req.AddClassBaseReqDTO;
import com.ll.domain.classbase.enums.ClassBaseStatusEnum;
import com.ll.dal.po.ClassBasePO;
import com.ll.domain.classbase.dto.ClassBaseDTO;
import com.ll.base.util.ScalarUtil;
import org.springframework.beans.BeanUtils;

import java.util.Arrays;

public class ClassBaseConvert {


    public static ClassBasePO addClassBaseReqDTO2PO(AddClassBaseReqDTO reqDTO){
        ClassBasePO po = new ClassBasePO();
        BeanUtils.copyProperties(reqDTO, po);
        po.setStatus(ClassBaseStatusEnum.待开班);
        return po;
    }

    public static ClassBaseDTO PO2DTO(ClassBasePO po){
        ClassBaseDTO dto = new ClassBaseDTO();
        if(po == null){
            return null;
        }
        BeanUtils.copyProperties(po, dto);
        dto.setStatusIndex(po.getStatus().ordinal());
        if(ScalarUtil.isNotEmpty(dto.getExtData()) && dto.getExtData().contains(ScalarUtil.DEFAULT_STRING_SPLIT)){
            String[] split = dto.getExtData().split(ScalarUtil.DEFAULT_STRING_SPLIT);
            dto.setStudentIds(Arrays.asList(split));
        }
        return dto;
    }

}
